package com.csaba.connector;

import java.util.HashMap;
import java.util.Map;

/**
 * FlowControlException indicates special forks in the process flow
 * instead of an error or normal exception. 
 * <p> Use this in services where it is possible to handle specific 
 * flows in bank specific components. The core components are considering
 * this exception similar to any other {@link ServiceException}.
 * <p> The exception is able to hold a stage ID that indetifies the special
 * stage in a process flows that should come after generating this
 * exceptions. StageID can be defined in bank specific classes. Sample
 * stage ID:
 * <p> <code>public final static String STAGE_SMSOTP = "com.csaba.connector.khb:SMSOTP";</code>
 * <p> The exception may carry parameters with it. For example if the password is going to expiry, the login
 * service may throw a FlowControlException, and it may carry the type of the password, and the time
 * when it will expiry. 
 * <p> Best approach is to subclass this FlowControlException and provide case specific parameters
 * that best fits to the situation.
 * 
 * @author user
 *
 */
public class FlowControlException extends ServiceException
{
	private static final long serialVersionUID = 3364040676523858235L;

	private final String stageId;
	private Map<String, Object> parameters;

	public FlowControlException( final String stageId )
	{
		super("Process flow should go to stage: " + stageId);

		this.stageId = stageId;
	}

	public String getStageId()
	{
		return stageId;
	}

	public void addParameter( final String key, final Object value )
	{
		if ( parameters == null )
		{
			parameters = new HashMap<String, Object>();
		}
		parameters.put(key, value);
	}

	public Object getParameter( final String key )
	{
		if ( parameters == null )
			return null;
		return parameters.get(key);
	}
}
